<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array('type <>'=>4,'merchid'=>0,'uniacid'=>$_SESSION['uniacid']);
	$params['onepluginname']='';
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:30;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
    $orderby='readnum desc,salenum desc';
	$total='';
	$return['list']=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,array('id','title','image','readnum'),'',$orderby);
	foreach($return['list'] as $k=>&$v){
		$v['total2']=pdo_count('jy_weishop_member_history',array('os'=>2,'goodsid'=>$v['id'],'uniacid'=>$_SESSION['uniacid']));
		$v['total1']=pdo_count('jy_weishop_member_history',array('os'=>array(1,6,7,8,9,13),'goodsid'=>$v['id'],'uniacid'=>$_SESSION['uniacid']));
		$v['total3']=pdo_count('jy_weishop_member_history',array('os'=>3,'goodsid'=>$v['id'],'uniacid'=>$_SESSION['uniacid']));
		$v['totalother']=$v['readnum']-$v['total1']-$v['total2']-$v['total3'];
	}
	$readnum=pdo_getsum('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid']),'readnum');
	$total2=pdo_count('jy_weishop_member_history',array('os'=>2,'uniacid'=>$_SESSION['uniacid']));
	$total1=pdo_count('jy_weishop_member_history',array('os'=>array(1,6,7,8,9,13),'uniacid'=>$_SESSION['uniacid']));
	$total3=pdo_count('jy_weishop_member_history',array('os'=>3,'uniacid'=>$_SESSION['uniacid']));
	$totalother=$v['readnum']-$v['total1']-$v['total2']-$v['total3'];
	$tips='总访问次数：'.$readnum.'次；微信访问：'.$total2.'次；小程序访问：'.$total1.'次；H5访问：'.$total3.'次；其他访问：'.$totalother.'次';
	$htmls=array(
		'type'=>'list',
		//'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>$tips,'delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'readnum','title'=>'总访问次数','type'=>'string'),	
			array('name'=>'total2','title'=>'微信访问','type'=>'string'),
			array('name'=>'total1','title'=>'小程序访问','type'=>'string'),
			array('name'=>'total3','title'=>'H5访问','type'=>'string'),
			array('name'=>'totalother','title'=>'其他访问','type'=>'string'),
		),'action'=>array(
			array('type'=>'href','op'=>'item','title'=>'访问详情')
		)),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='item'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['id']){
		$params['goodsid']=$_RQ['id'];
		$return['params']['id']=$_RQ['id'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 30;
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_weishop_member_history',$params,array($pindex,$psize),$total,'','',$orderby);
	foreach($return['list'] as $k=>&$v){
		$v['member']=cfc('core')->member_show($v['mid']);
		$v['goodstitle']=pdo_getcolumn('jy_weishop_goods',array('id'=>$v['goodsid'],'uniacid'=>$_SESSION['uniacid']),'title');
	}
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'os','title'=>'访问类型','type'=>'radio','options'=>'os'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','op'=>'item','title'=>'访问详情')
		)),
	);
	$return['os']=get_ostitle();
	$return['htmls']=$htmls;
	exi($return);
}
